package vip.ola.pay.batchpay;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.URL;
import java.net.URLConnection;


public class HttpClientUtil {

	public int count = 0;
	

	public static String submitPost(String url, String paramContent,String charSet, int connTimeOut,int soTimeOut) {
		StringBuffer message = null;
		URLConnection connection = null;
		URL reqUrl = null;
		OutputStreamWriter reqOut = null;
		InputStream in = null;
		BufferedReader br = null;
		String param = paramContent;
		// String identifier = System.currentTimeMillis() + "";
		if(null==charSet||"".equals(charSet)){
			charSet="GBK";
		}
		try {
			message = new StringBuffer();
			reqUrl = new URL(url);
			connection = reqUrl.openConnection();
			connection.setReadTimeout(soTimeOut);
			connection.setConnectTimeout(connTimeOut);
			connection.setDoOutput(true);
			reqOut = new OutputStreamWriter(connection.getOutputStream(),charSet);
			reqOut.write(param);
			reqOut.flush();
			int charCount = -1;
			in = connection.getInputStream();
			br = new BufferedReader(new InputStreamReader(in, charSet));
			while ((charCount = br.read()) != -1) {
				message.append((char) charCount);
			}
		} catch (Exception ex) {
			ex.printStackTrace();
			return "EXCEPTION";
		} finally {
			try {
				in.close();
				reqOut.close();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return message.toString();
	}



}
